package com.chixing.ih.module.task.mapper;

import com.chixing.ih.common.IhRepository;
import com.chixing.ih.module.task.mapper.provider.CommentMapperProvider;
import com.chixing.ih.module.task.pojo.Comment;
import com.chixing.ih.module.task.pojo.DTO.CommentDTO;
import com.chixing.ih.module.task.pojo.Reply;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 目的:
 *
 * @author ：zcw
 * @version: 1.0  2020/9/25 23:01
 */
@Mapper
public interface CommentMapper extends IhRepository<Comment> {

    /**
     * 获取该文章或资源下的所有评论
     *
     * @param taskId 文章或资源id
     * @return
     */
    @SelectProvider(value = CommentMapperProvider.class, method = "findByTaskId")
    @Results(id = "commentMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "comm_context", property = "commContext"),
            @Result(column = "comm_state", property = "commState"),
            @Result(column = "create_time", property = "commCreateTime"),
            @Result(column = "delete_time", property = "commDeleteTime"),
            @Result(column = "task_id", property = "taskId"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "is_deleted", property = "logicalDeletion")
    })
    List<CommentDTO> findByTaskId(Long taskId);

    /**
     * 获取二级评论
     *
     * @param commentId
     * @return
     */

    @SelectProvider(value = CommentMapperProvider.class, method = "findSecondComment")
    @Results(id = "commentMaps", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "reply_content", property = "replyContent"),
            @Result(column = "reply_comment_id", property = "replyCommentId"),
            @Result(column = "reply_replyuser_id", property = "replyReplyUserId"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "reply_createtime", property = "replyCreateTime"),
            @Result(column = "reply_top", property = "replyTop"),
            @Result(column = "is_deleted", property = "logicalDeletion")
    })
    List<Reply> findSecondComment(Long commentId);

    /**
     * 获取三级评论
     *
     * @param commentId
     * @return
     */

    @SelectProvider(value = CommentMapperProvider.class, method = "findThirdComment")
    @ResultMap({"commentMaps"})
    List<Reply> findThirdComment(Long commentId);


    /**
     * 添加子评论或回复评论
     *
     * @param reply
     * @return
     */
    @InsertProvider(value = CommentMapperProvider.class, method = "addSonComments")
    boolean addSonComments(Reply reply);

    /**
     * 添加父评论
     *
     * @param comment
     * @return
     */
    @InsertProvider(value = CommentMapperProvider.class, method = "addRootComments")
    boolean addRootComments(Comment comment);
}
